package com.jiazhong.example.project.bookstore.front.listener;
// 订单消费者

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jiazhong.example.project.bookstore.commons.bean.Order;
import com.jiazhong.example.project.bookstore.commons.bean.RocketMQOrder;
import com.jiazhong.example.project.bookstore.front.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
//@RocketMQMessageListener(consumerGroup = "order_success_4", topic = "Order", selectorExpression = "transaction", messageModel = MessageModel.BROADCASTING)
@Component
public class OrderSuccessOrderListener implements RocketMQListener<String> {
    @Resource
    private OrderService orderService;

    @Override
    public void onMessage(String s) {
        log.info("开始执行成功订单修改操作");
        RocketMQOrder rocketMQOrder = JSONArray.parseObject(s, RocketMQOrder.class);
        log.info("订单，rocketMQOrder:{}", rocketMQOrder);
        UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", rocketMQOrder.getOrderId());
        updateWrapper.set("status", 3);
        orderService.update(updateWrapper);
    }
}
